# Contributor: rubicon <rubicon@mailo.com>
# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=ocaml-cairo2
_pkgname=cairo2
pkgver=0.6.2
pkgrel=2
pkgdesc="OCaml bindings to Cairo, a 2D Vector Graphics Library"
url="https://github.com/Chris00/ocaml-cairo"
arch="all !riscv64 !loongarch64" # ocaml
license="LGPL-3.0-only"
depends_dev="$pkgname=$pkgver-r$pkgrel"
makedepends="
	dune
	dune-configurator-dev
	ocaml
	ocaml-compiler-libs
	ocaml-csexp-dev
	cairo-dev
	"
options="!check"
subpackages="$pkgname-dev"
source="$pkgname-$pkgver.tar.bz2::https://github.com/Chris00/ocaml-cairo/releases/download/$pkgver/cairo2-$pkgver.tbz"
builddir="$srcdir/$_pkgname-$pkgver"

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	export OCAMLPATH=/usr/lib/ocaml
	dune build -p cairo2 @install --no-buffer --verbose
}

check() {
	dune runtest --no-buffer --verbose
}

package() {
	dune install \
		--destdir="$pkgdir" \
		--prefix=/usr \
		--libdir=/usr/lib/ocaml \
		cairo2

	rm -Rf "$pkgdir"/usr/doc
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; find usr/lib/ocaml \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\) | while read -r path
	do
		amove "$path"
	done
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
789b65428855c3b8fb71836ee6e607870c3140a6152fb01b8ba6e7d2e2f4842a62412061a5eff99023234d305587b605d0cbbacd29456c86a52e9df6466bd302  ocaml-cairo2-0.6.2.tar.bz2
"
